#include "FadeOutAnimation.h"
#include "GraphicalElement.h"

FadeOutAnimation::FadeOutAnimation(unsigned long duration)
    : Animation(duration), alpha(255)
{
}

FadeOutAnimation::~FadeOutAnimation()
{
}

void FadeOutAnimation::update(double factor)
{
    if (factor >= 1)
    {
        alpha = 0;
        return;
    }
    alpha = 255*(1-factor);
}

void FadeOutAnimation::render(const Position& parent)
{
    element->getTexture()->setAlpha(alpha);
    Animation::render(parent);
    element->getTexture()->setAlpha(255);
}
